package com.zyc.dao;

import com.zyc.vo.RequestInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

// 操作请求信息表数据库
@Repository
public interface RequestRepository extends JpaRepository<RequestInfo, Long> {

    // 根据performId,删除某一次的并发测试记录
    int deleteByPerformId(String performId);


    // 统计每次并发,各IP服务器调用数量
    @Query(value = "select perform_id as performId, ip_address as ipAddress, count(*) as totalCount " +
            "from request_info " +
            "group by perform_id, ip_address order by perform_id desc ", nativeQuery = true)
    List<Map<String, Object>> findRequestInfoIPList();

    // 统计每次并发,各策略方式调用数量
    @Query(value = "select perform_id as performId, request_type as requestType, count(*) as totalCount " +
            "from request_info " +
            "group by perform_id, request_type order by perform_id desc ", nativeQuery = true)
    List<Map<String, Object>> findRequestInfoTypeList();

}
